package cn.iocoder.yudao.module.mqtt.framework.util;

/**
 * MQTT上下文持有者
 * 用于在线程间传递MQTT相关信息
 *
 * @author 芋道源码
 */
public class MqttContextHolder {

    private static final ThreadLocal<String> CLIENT_ID_HOLDER = new ThreadLocal<>();
    private static final ThreadLocal<Long> CONFIG_ID_HOLDER = new ThreadLocal<>();

    /**
     * 设置客户端ID
     */
    public static void setClientId(String clientId) {
        CLIENT_ID_HOLDER.set(clientId);
    }

    /**
     * 获取客户端ID
     */
    public static String getClientId() {
        return CLIENT_ID_HOLDER.get();
    }

    /**
     * 设置配置ID
     */
    public static void setConfigId(Long configId) {
        CONFIG_ID_HOLDER.set(configId);
    }

    /**
     * 获取配置ID
     */
    public static Long getConfigId() {
        return CONFIG_ID_HOLDER.get();
    }

    /**
     * 清理上下文
     */
    public static void clear() {
        CLIENT_ID_HOLDER.remove();
        CONFIG_ID_HOLDER.remove();
    }
} 